package com.sun.tv;

import java.text.DecimalFormat;
import java.util.HashMap;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Handler;

import com.tools.HttpInterface;
import com.tools.MyLog;
import com.tools.SysInterfacePhone;

public class ClkBrowser extends Click {
	HashMap<String, String> table = new HashMap<String, String>();
	
	@Override
	boolean onClick(Context context, AdConfig config) {
		if (context == null)
			return false;
		TVAdView adView = weakContext.get();
		if (adView == null)
			return false;
		String url = table.get(CONFIG_NAME_ANDROID);
		if (url == null || url.length() < 1)
			url = table.get(CONFIG_NAME_DEFAULT);
		if (url == null || url.length() < 1)
			return false;
		url = url.trim();
		MyLog.i("UserLocation:ClkBrowser: url = " + url);
		if (url.length() <= 0 || url.length() < 1)
			return false;		
		return clickSysBrowser(adView, url);
	}

	private boolean clickSysBrowser(TVAdView adView, String url) {
		try {
			return SysInterfacePhone.invoker().openSysBrowser(
					adView.contextWeakReference.get(), url);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	void startElement(String localName, String qName, Attributes atts)
			throws SAXException {
		if (localName.equals("url")) {
			int con = atts.getLength();
			if (con >= 2) {
				table.put(atts.getValue("os"), atts.getValue("value"));

			}
		}
	}

	@Override
	void endElement(String localName, String qName, String content)
			throws SAXException {

	}

}
